package com.example.everying.framework.websocket.factory;

import com.example.everying.framework.websocket.handler.*;
import com.example.everying.model.entity.chat.ChatConversationEntity;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

@Slf4j
public class MessageHandlerFactory {
    private static final Map<String, MessageHandler> handlers = new HashMap<>();
    static {
        handlers.put("send", new SendMessageHandler()); // 发送消息
        handlers.put("read", new ReadMessageHandler()); // 读取消息
        handlers.put("typing",  new TypingStatusHandler()); // 新增输入状态处理器
        handlers.put("recall",  new RecallMessageHandler()); // 新增撤回处理器
        handlers.put("heartbeat",  new HeartbeatHandler()); // 新增心跳处理器
        handlers.put("pinned",  new PinnedMessageHandler()); // 新增会话置顶处理器
        handlers.put("messageList",  new MessageListHandler()); // 新增会话列表处理器
        handlers.put("commentList",  new CommentListMessageHandler()); // 新增评论列表处理器
        handlers.put("historyList",  new HistoryListMessageHandler()); // 历史记录列表处理器
        handlers.put("sysNotice",  new NoticeMessageHandler()); // 系统通知处理器
        handlers.put("commentMessage",  new CommentMessageHandler()); // 评论通知处理器
        handlers.put("applyStatusMessage",  new ApplyStatusMessageHandler()); // 申请通知处理器
        handlers.put("applyInfoMessage",  new ApplyInfoMessageMessageHandler()); // 申请通知处理器
        handlers.put("locationMessage",  new LocationMessageMessageHandler()); // 位置信息处理器
        handlers.put("cardMessage",  new CardMessageMessageHandler()); // 卡片处理器
        handlers.put("sysNoticeNumMessage",  new NoticeNumMessageMessageHandler()); // 通知条数通知处理器
        handlers.put("noticeUnreadStatusMessage",  new NoticeUnreadStatusMessageHandler());
        handlers.put("navigationRedDotMessage", new NavigationRedDotMessageHandler()); // 导航栏红点消息
        handlers.put("chatConversationDelete", new ChatConversationMessageHandler()); // 会话删除处理器


    }


    public static MessageHandler getHandler(String type) {
        if (!type.equals("heartbeat")){
            log.info("获取消息处理程序: {}", type);
        }
        MessageHandler handler = handlers.get(type);
        if (handler == null) {
            throw new RuntimeException(type);
        }
        return handler;
    }

}
